package com.googlecode.androidutils.database;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

/**
 * This class provides utility methods to work more easily with
 * {@link SQLiteDatabase}s.
 *
 * @author Patrick Kranz
 */
public class SQLiteDatabaseUtils {

  /* Private constructor prevents instantiating */
  private SQLiteDatabaseUtils() {}

    /**
   * Silently closes the given database. It is safe to pass in a closed database
   * or even <code>null</code>.
   *
   * @param database
   *          the database to close
   */
  public static void closeQuietly(final SQLiteDatabase database) {
    if ((database != null) && database.isOpen()) {
      database.close();
    }
  }

  /**
   * Silently closes the given cursor. It is safe to pass in a closed cursor or
   * even <code>null</code>.
   *
   * @param cursor
   *          the cursor to close
   */
  public static void closeQuietly(Cursor cursor) {
    if ((cursor != null) && !cursor.isClosed()) {
      cursor.close();
    }
  }
}
